import redis.clients.jedis.Jedis;

public class TestString {
    public static void main(String[] args) {
        Jedis jedis = new Jedis("IP地址",6379);
        System.out.println(jedis.ping("hello Jedis"));
        System.out.println(jedis.keys("*"));//查看所有的key
        //[money, out]
        System.out.println(jedis.exists("money"));//判断是否存在该key
        //true
        System.out.println(jedis.append("money","666"));//追加一个字符串
        //4
        System.out.println(jedis.strlen("money"));//查看当前字符串的长度
        //7
        System.out.println(jedis.incr("out"));//自增1
        System.out.println(jedis.decr("out"));//自减1
        System.out.println(jedis.incrBy("out",10));//设置增步长
        System.out.println(jedis.decrBy("out",10));//设置减步长
        System.out.println(jedis.getrange("money",0,3));//截取0-3的字符串
        System.out.println(jedis.setrange("money",1,"replace"));
        System.out.println(jedis.setex("k1",20,"hello"));//设置过期时间
        System.out.println(jedis.setnx("k2","redis"));//设置一个不存在的key，如果存在，则创建不成功
        System.out.println(jedis.mset("k1","v1","k2","v2"));//同时设置多个key-value
        System.out.println(jedis.mget("k1","k2"));//同时获取多个key
        System.out.println(jedis.msetnx("k1","v1","k2","v2"));//同时设置多个不存在的值
        System.out.println(jedis.mset("user:1:name","zhangsan","user:1:age","2"));//设置一个对象
        System.out.println(jedis.getSet("k1","k9"));//先获取再赋值
        /**
         * 其余的都与redis.md中的一致，不再复写
         * */
    }
}
